<template>
  <div
    class="search-bar"
    :style="{
      color: property.textColor,
    }"
  >
    <!-- 搜索框 -->
    <div
      class="inner"
      :style="{
        height: `${property.style.height}px`,
        background: property.backgroundColor,
        borderRadius: `${property.borderRadius}px`,
        flex: property.cartBtn.show ? '1' : 'unset',
        width: property.cartBtn.show ? 'auto' : '100%',
      }"
    >
      <div class="inner-left">
        <Icon icon="ep:search" />
        <span>{{ property.placeholder || '搜索商品' }}</span>
      </div>
      <div class="inner-right">
        <!-- 搜索热词 -->
        <span v-for="(keyword, index) in property.hotKeywords" :key="index" class="hot-keyword">{{ keyword }}</span>
        <!-- 扫一扫 -->
        <Icon icon="ant-design:scan-outlined" v-show="property.showScan" />
        <div :style="{
        height: `${property.btnHeight}px`,
        color: property.btnTxtColor,
        fontSize: `${property.btnTxtSize}px`,
        background: property.BtnBgColor,
        borderRadius: `${property.btnRadius}px`,
        width: `${property.btnWidth}px`,
      }" class="btns" v-show="property.showBtn">
          搜索
        </div>
      </div>
    </div>

    <!-- 购物车 -->
    <div v-if="property.cartBtn.show" class="cart-btn-wrap">
      <img :src="property.cartBtn.iconUrl" class="cart-icon" alt="购物车" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { color } from 'echarts';
import { SearchProperty } from './config'
/** 搜索框 */
defineOptions({ name: 'SearchBar' })
defineProps<{ property: SearchProperty }>()
</script>

<style scoped lang="scss">
.search-bar {
  display: flex;
  align-items: center;
  z-index: 11;
}
.btns{
  display: flex;
  align-items: center;
  justify-content: center;
}
.inner {
  position: relative;
  display: flex;
  min-height: 28px;
  font-size: 14px;
  align-items: center;
  flex: 1;
  justify-content: space-between;
}

.inner-left {
  display: flex;
  align-items: center;
  gap: 2px;
}

.inner-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hot-keyword {
  margin-right: 4px;
  font-size: 12px;
  color: #888;
}

.right {
  position: absolute;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.cart-btn-wrap {
  display: flex;
  margin-left: 8px;
  align-items: center;
}

.cart-icon {
  width: 24px;
  height: 24px;
}
</style>
